﻿using ParkSaleForAdmin.Data;

namespace ParkSaleForAdmin
{
    public class ParkInfo : IBaseData<ParkInfo>
    {
        public int id
        {
            get;
            set;
        }
        public int location
        {
            get;
            set;
        }
        public double price
        {
            get;
            set;
        }
        public int number
        {
            get;
            set;
        }
        public int status
        {
            get;
            set;
        }
        public string note
        {
            get;
            set;
        }

        public ParkInfo Parse(DatabaseData data)
        {
            id = int.Parse(data["id"].Value);
            number = int.Parse(data["number"].Value);
            status = int.Parse(data["status"].Value);
            price = double.Parse(data["price"].Value);
            location = int.Parse(data["location"].Value);
            note = data["note"].Value;
            return this;
        }
    }
    public class ParkWindow : BasicManagerWindow<ParkInfo>
    {
        public ParkWindow()
        {

            BeginToCreate();
            Title = "车位管理";
        }
        public override string TableName => "Park";

        protected override string[] values => new string[] { "id", "location", "price", "number", "status", "note" };

        protected override string[] titles => new string[] { "车位代号", "所属小区代号", "价格", "小区内车位号", "车位状态", "备注" };

        protected override string[] InputBoxTitle => new string[] { "所属小区代号", "价格", "小区内车位号", "车位状态", "备注" };

        protected override string[] InputBoxValue => new string[] { "location", "price", "number", "status", "note" };

        protected override string[] BindingName => new string[] { "id", "location", "price", "number", "status", "note" };

        protected override bool EachArgForAppend(string n, string value)
        {
            if (n.Equals("note"))
            {
                return true;
            }
            else if (n.Equals("price"))
            {
                double d;
                if (double.TryParse(value, out d))
                {
                    return true;
                }
                return false;
            }
            else
            {
                int d;
                if (int.TryParse(value, out d))
                {
                    if (n.Equals("status") && (d < -1 || d > 1))
                    {
                        return false;
                    }
                    return true;
                }
                else
                    return false;
            }

        }


        public override string AppendStr(ParkInfo obj)
        {
            return $"select * from {TableName} where id=99999";
        }

        public override string ChangeStr(ParkInfo obj)
        {
            return $"select * from {TableName} where id = {obj.id}";

        }

        public override string DeleteStr(ParkInfo obj)
        {
            return $"select * from {TableName} where id = {obj.id}";
        }
    }
}
